package com.hwl.sms.controller;

import com.hwl.commonutils.result.RespBean;
import com.hwl.commonutils.utils.FormUtils;
import com.hwl.sms.service.SmsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Api(tags = "短信发送服务")
@RestController
@RequestMapping("/api/sms")
public class SmsController {

    @Resource
    private SmsService smsService;

    @ApiOperation("发送短信验证码")
    @GetMapping("send/{phone}")
    public RespBean getCode(@PathVariable String phone) {
        if (StringUtils.isEmpty(phone) || !FormUtils.isMobile(phone)) {
            return RespBean.error().message("请输入正确的手机号码！");
        }
        return smsService.send(phone);
    }
}
